def prost(numb):
    for i in range(2, numb):
        if numb%i==0:
            return False
    return True

def nearestProst(numb):
    if prost(numb):
        return numb
    else:
        count = 1
        while count < numb:
            numbUp = numb+count
            numbDown = numb-count

            isNumbUp = prost(numbUp)
            isNumbDown = prost(numbDown)

            if isNumbUp and isNumbDown: return numbDown
            elif isNumbUp and not isNumbDown: return numbUp
            elif isNumbDown and not isNumbUp: return numbDown

            count+=1

def toInput():
    userInput = input().split()
    numbers = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
    numb = ""
    for i in userInput:
        try:
            numb+=str(numbers.index(i))
        except:
            return False, 0
    if numb[0] == "0" or len(numb) != 3:
        return False, 0
    return True, numb

flag, userInput = toInput()
if flag: print(nearestProst(int(userInput)))
else: print("Wrong input")